using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using Common;

using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace AdminTools
{
    partial class ViewAdminTools : PortalModuleBase, IActionable
    {

        #region Private Members
        #endregion

        #region Public Methods

        public bool DisplayAudit()
        {
            bool retValue = false;

            if ((string)Settings["auditinfo"] == "Y")
            {
                retValue = true;
            }

            return retValue;
        }

        #endregion

        #region Event Handlers

        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    lblNumOfProduct.Text = GetNumOfProduct().ToString();
                    lblNumOfBuyRequest.Text = GetNumOfBuyRequest().ToString();
                    lblNumOfEnterprise.Text = GetNumOfEnterprise().ToString();
                    lblNumOfMachine.Text = GetNumOfMachine().ToString();
                    lblNumOfSoftSolution.Text = GetNumOfSoftSolution().ToString();
                    lblNumOfService.Text = GetNumOfService().ToString();
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion

        #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Registers the module actions required for interfacing with the portal framework
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection Actions = new ModuleActionCollection();
                Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl(), false, SecurityAccessLevel.Edit, true, false);
                return Actions;
            }
        }

        #endregion

        #region private method

        private int GetNumOfProduct()
        {
            string SQLCmd = "SELECT count(productId) FROM tm_product WHERE status ='" + consts.constStatusENABLE + "'";
            return sysLibs.ExecuteScalar(SQLCmd, sysLibs.GetConnectionString);
        }

        private int GetNumOfBuyRequest()
        {
            string SQLCmd = "SELECT count(requestId) FROM tm_buy_request WHERE status ='" + consts.constStatusENABLE + "'";
            return sysLibs.ExecuteScalar(SQLCmd, sysLibs.GetConnectionString);
        }

        private int GetNumOfEnterprise()
        {
            string SQLCmd = "SELECT count(userId) FROM tm_users WHERE usersStatus ='" + consts.constStatusENABLE + "' AND userType & " + consts.constSYSBitPos + " = 0 ";
            return sysLibs.ExecuteScalar(SQLCmd, sysLibs.GetConnectionString);
        }

        private int GetNumOfMachine()
        {
            string SQLCmd = "SELECT count(productId) FROM tm_product WHERE status ='" + consts.constStatusENABLE + "' AND productType = '" + consts.constProductMachine + "'" ;
            return sysLibs.ExecuteScalar(SQLCmd, sysLibs.GetConnectionString);
        }

        private int GetNumOfSoftSolution()
        {
            string SQLCmd = "SELECT count(productId) FROM tm_product WHERE status ='" + consts.constStatusENABLE + "' AND productType = '" + consts.constProductSoftSolution + "'";
            return sysLibs.ExecuteScalar(SQLCmd, sysLibs.GetConnectionString);
        }

        private int GetNumOfService()
        {
            string SQLCmd = "SELECT count(productId) FROM tm_product WHERE status ='" + consts.constStatusENABLE + "' AND productType = '" + consts.constProductService + "'";
            return sysLibs.ExecuteScalar(SQLCmd, sysLibs.GetConnectionString);
        }
             #endregion
}
}

